<template>
  <el-dialog :title="title" :visible="visible" @close="close">
    <el-form
      ref="form"
      :model="entityData"
      :rules="rules"
      label-width="80px"
      label-position="right"
      style="width:90%;margin:0px auto;"
    >
      <el-form-item label="上级" prop="parentId">
        <organization-single-select
          v-model="entityData.parentId"
          :name="entityData.parentName"
          @changeSelect="changeSelect"
        />
      </el-form-item>

      <el-form-item label="名称" prop="name">
        <el-input v-model="entityData.name" />
      </el-form-item>
      <el-form-item label="编码" prop="code">
        <el-input v-model="entityData.code" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <dictionary-radio-group
          v-model="entityData.status"
          :code="constant.DICTIONARY_TYPE_CODES.STATUS"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <dictionary-radio-group
          v-model="entityData.type"
          :code="constant.DICTIONARY_TYPE_CODES.ORGANIZATION_TYPE"
        />
      </el-form-item>
      <el-form-item label="排序号">
        <el-input v-model="entityData.orderNo" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="entityData.remark" type="textarea" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-show="saveButtonVisible" type="primary" @click="save">保存</el-button>
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { detailMixin } from '@/mixin/detailMixin'

const MODULE_CODE = 'system'
const ENTITY_TYPE = 'organization'
export default {
  name: ENTITY_TYPE + '-detail',

  mixins: [detailMixin],
  props: {
    parentId: {
      type: String,
      default: '',
      required: false
    },
    parentName: {
      type: String,
      default: '',
      required: false
    }
  },
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      entityData: {
        parentId: this.parentId,
        parentName: this.parentName
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择类型', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'blur' }
        ]

      },
      currentRow: {}
    }
  },
  watch: {
    parentName: function () {
      this.entityData.parentId = this.parentId
      this.entityData.parentName = this.parentName
    }
  },
  methods: {
    changeSelect(value, name) {
      this.entityData.parentId = value
      this.entityData.parentName = name
    }
  }

}
</script>

<style lang="scss">
</style>
